package DAL;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;

import DALFacades.IFacade;
import Helpers.ApplicationLogger;

public final class Pipeline {

    private static final class Nested
    {
        static final Pipeline _instance = new Pipeline();
    }

    public static Pipeline getInstance()
    {
        return Nested._instance;
    }
    
    public IFacade getFacade()
    { 
    	Context ctx = null;
   	 	try {
			ctx = new InitialContext();
    	 } catch (NamingException e) {
    		 ApplicationLogger.getInstance().LOG.error(e.getMessage());
    	 } 
    	 
    	 Object result = null;
    	 
    	 try {
    		ApplicationLogger.getInstance().LOG.info("Trying to load facade");
			result = ctx.lookup("Facade");
			ApplicationLogger.getInstance().LOG.info("Facade " + result.getClass().getName() + " loaded");
		} catch (NamingException e) {
			 ApplicationLogger.getInstance().LOG.error(e.getMessage());
		}
		return (IFacade)result;
    }
}
